<?php
class cJsForm
        {
        var $properties;//arrays (name=>value, value) (mixed array)
        var $select_tag_properties; //$default, $arrays, $default_name="", $restore_default=false
        var $compulsory="<FONT COLOR=\"#FF0000\" FONT SIZE=\"4\" >  *</FONT>";
        function getProperties()
                {
		$name=$this->properties["id"];
                foreach($this->properties as $key=>$value)
			{
			if($key=='onclick' || $key=='onchange' || $key=='onblur')
				$property.=(!is_int($key))?"var_".$name.".".$key."="."$value; \n":"\"$value \";";
			else
				$property.=(!is_int($key))?"var_".$name.".".$key."="."\"$value\"; \n":"$value ";
			}
		unset($this->properties);
                return $property;
                }

        function startForm()
                {
                return "<form ".$this->getProperties()." >";
                }

        function generateInputTag()
                {
		$js="var var_".$this->properties[id]." =  document.createElement('INPUT');\n";
                return "$js ".$this->getProperties();
                }

        function generateSelectTag()
                {

		$name=$this->properties["id"];

		$js="var var_".$name." =  document.createElement('SELECT');\n";
                $js.=$this->getProperties();

		$js.="var opt_".$name." =  document.createElement('OPTION');\n";

		if ($this->select_tag_properties["default"]=="" || $this->select_tag_properties["restore_default"]==true)
			{
			$this->select_tag_properties["default_name"]=($this->select_tag_properties["default_name"])?$this->select_tag_properties["default_name"]:"--Select--";
			$js.="var_$name.options[0]=new Option('$this->select_tag_properties[default_name]','');";
			}

                if($this->select_tag_properties["arrays"])
                        {
                        for($i=0;$i< count($this->select_tag_properties["arrays"]);$i++)
                                $names[]=array_values($this->select_tag_properties["arrays"][$i]);

                        foreach($names as $key=>$value)
                                {
                                $value_array[]=$value[0];
                                $name_array[]=($value[2])?$value[2]:$value[0];
                                }

                        for($i=0;$i< count($name_array);$i++)
                                {
				$js.="var_$name.options[$i]=new Option('$name_array[$i]','$value_array[$i]');";
				}
                        }
		return $js;


/*		$select_code="<select ".$this->getProperties()." >";
                if ($this->select_tag_properties["default"]=="" || $this->select_tag_properties["restore_default"]==true)
                        {
                        $this->select_tag_properties["default_name"]=($this->select_tag_properties["default_name"])?$this->select_tag_properties["default_name"]:"--Select--";
                        $select_code.="<option value=\"\" ";
                        $select_code.=($this->select_tag_properties["default"]=="" || $this->select_tag_properties["default"][0]=="")?" selected ":"";
                        $select_code.=">".$this->select_tag_properties["default_name"]."</option>";
                        }
                if($this->select_tag_properties["arrays"])
                        {
                        for($i=0;$i< count($this->select_tag_properties["arrays"]);$i++)
                                $names[]=array_values($this->select_tag_properties["arrays"][$i]);

                        foreach($names as $key=>$value)
                                {
                                $value_array[]=$value[0];
                                $name_array[]=($value[1])?$value[1]:$value[0];
                                }

                        for($i=0;$i< count($name_array);$i++)
                                {
                                $select_code.="<option value=\"$value_array[$i]\" ";
                                $select_code.=($this->select_tag_properties["default"] && is_array($this->select_tag_properties["default"]))?((in_array($value_array[$i],$this->select_tag_properties["default"]))?"selected":""):(($value_array[$i]==$this->select_tag_properties["default"])?"selected":"");
                                $select_code.=" >$name_array[$i]</option>";
                                }
                        }
                $select_code.="</select>";
                return $select_code;*/
                }

        function endForm()
                {
                return "</form>";
                }
        }
?>
